
Ext.define('xyc.view.HandOrSale', {
    extend: 'Ext.Panel',
    xtype: 'handorsale',
    requires: [
        'xyc.model.Purchase'
    ],
    config: {
        layout: 'card',
        groupByDay: true,
        loadingText: '加载中...'
    },
    initialize: function () {
        this.callParent();
        this.searchstore = new Ext.data.Store({
            model: 'xyc.model.Purchase',
            autoLoad: false,
            sorters: '',
            proxy: {
                type: 'ajax',
                url: server + '/ext/com.cinsea.mobile.ext.XycAction?action=gethandsalelist',
                params: {processid: this.processid},
                reader: {
                    type: 'json',
                    totalProperty: 'totalCount',
                    rootProperty: 'result'
                }

            }
        })
        this.list = new Ext.List({
            itemTpl: '<span class="name">类型:{type}总价：{total}({price}×{num}) {place3}（{place2}）</span>',
            loadingText: false,
            store: this.searchstore
        });


        this.listpanel = new Ext.Panel({
            items: this.list,
            layout: 'fit'
        });


        this.listpanel.add({
            xtype: 'toolbar',
            docked: 'top',
            layout: { pack: 'left' },
            items: [
                {
                    ui: 'back',
                    text: '返回',
                    scope: this,
                    handler: function () {
                        this.getParent().setActiveItem(this.prevCard, {
                            type: 'slide',
                            reverse: true,
                            scope: this,
                            after: function () {
                                this.destroy();
                            }
                        });
                    }
                },
                { xtype: 'spacer' },
                {
                    text: '确认送货',
                    scope: this,
                    handler: function () {
                        Ext.Ajax.request({
                            url: server + '/ext/com.cinsea.mobile.ext.XycAction?action=sendhandsale',
                            params: {processid: this.processid},
                            scope: this,
                            success: function (response, opts) {
                                if (response.responseText == 'success') {
                                    this.prevCard.refresh();
                                    this.getParent().setActiveItem(this.prevCard, {
                                        type: 'slide',
                                        reverse: true,
                                        scope: this,
                                        after: function () {
                                            this.destroy();
                                        }
                                    });
                                }
                                else
                                    Ext.Msg.alert(response.responseText);
                            },
                            failure: function (response, opts) {
                                Ext.Msg.alert('网络异常');
                            }
                        });

                    }
                }
            ]
        });

        // Take off the spinner
        //this.list.el.unmask();

        this.add(this.listpanel);

    },
    setProcessid: function (processid, title) {
        this.listpanel.down('toolbar').setTitle('<font size= 2>'+title+'</font>');
        this.processid = processid;
        this.searchstore.getProxy().setExtraParam('processid', processid);
        this.searchstore.load();
    },
    setPrevcard: function (prevc) {
        this.prevCard = prevc;

    }

});

